﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess;
using ExaminationSys.DataAccess.Entity;
using Ext.Net;
using ExaminationSys.DataAccess.Repository;
using System.Xml.Linq;
using System.Text;

namespace ExaminationSys.View.Student
{
    public partial class StudyCenter : System.Web.UI.Page
    {
        private static readonly SectionInfoService ProxySectionInfo = ObjectFactory<SectionInfoService>.Create();
        private static readonly PaperInfoService ProxyPaperInfo = ObjectFactory<PaperInfoService>.Create();
         private static readonly SectionLinkService ProxySectionlink = ObjectFactory<SectionLinkService>.Create();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!X.IsAjaxRequest)
            {
                SectionInfoDetail_RefreshData();

                // 引入样式表

                Literal cssControl = new Literal();

                cssControl.Text = "<link href=\"../../css/StudyCenter.css\" rel=\"stylesheet\" type=\"text/css\"/>";

                Page.Header.Controls.Add(cssControl);
            }
        }

        private int pageSize = 6;
        public static PageEntity PageEntity = null;
        public List<SectionInfoIntegrated> SectionInfoIntegratedList = new List<SectionInfoIntegrated>();
        public StringBuilder htmlStr = new StringBuilder();

        protected void SectionInfoDetail_RefreshData()
        {

            //获取学习栏目和外连接
            string sqlWhere = " SectionTypeID=1 or SectionTypeID=2   and  status<>0";
            int pageIndex = 0;

            int totalPage, totalRecord;
            var secionInfolist = ProxySectionInfo.GetListByPage(sqlWhere, " OrderIndex asc,OperatorTime desc", pageSize, pageIndex, out totalPage, out totalRecord);
            foreach (var i in secionInfolist)
            {
                if (string.IsNullOrEmpty(i.Img))
                {
                    i.Img = "../../images/defaultSection.png";
                }
                else
                {
                    i.Img = "../.." + i.Img;
                }
            }

            //获取所有试卷
            var paperInfoList = ProxyPaperInfo.GetAll();

            foreach(var s in secionInfolist)
            {
                var paperlist = new List<PaperInfo>() ;
                foreach(var p in paperInfoList){
                    if(p.SectionID == s.ID){
                      paperlist.Add(p);
                    }
                }
                SectionInfoIntegratedList.Add(new SectionInfoIntegrated(s, paperlist));
            }
 

            //获取所有外链接

        

            var sectionlinkList = ProxySectionlink.GetAll();
            foreach(var s in secionInfolist)
            {
                var sectionlink = (from i in sectionlinkList where i.SectionID == s.ID select i).ToList();
                if (sectionlink != null && sectionlink.Count > 0)
                {
                    SectionInfoIntegratedList.Add(new SectionInfoIntegrated(s, sectionlink.First()));
                }
            }

        }

      
    }

    
}